package com.bgys.user;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.function.Predicate;

import static springfox.documentation.builders.PathSelectors.regex;

/**
 * swagger配置
 * Enable open api 3.0.3 spec
 * @author 悲歌易水
 */
@EnableOpenApi
@Configuration
public class UserlSwaggerConfig {
    @Bean
    public Docket userApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("graph-user")
                .apiInfo(apiInfo())
                .select()
                .paths(paths())
                .build();
//                .securitySchemes(Collections.singletonList(oauth()))
//                .securityContexts(Collections.singletonList(securityContext()));
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("用户管理")
                .description("")
                .termsOfServiceUrl("http://springfox.io")
                .contact(new Contact("beigeyishui", "", ""))
                .license("Apache License Version 2.0")
                .licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE")
                .version("1.0.0")
                .build();
    }

    private Predicate<String> paths() {
        return regex("/user/*");
    }
}
